package com.cbj.db_work.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cbj.db_work.entity.Player;
import com.cbj.db_work.entity.vo.PlayerVo;
import com.cbj.db_work.mapper.PlayerMapper;
import com.cbj.db_work.service.PlayerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cbj
 * @since 2021-06-30
 */
@Service
public class PlayerServiceImpl extends ServiceImpl<PlayerMapper, Player> implements PlayerService {

    @Override
    public boolean addPlayer(PlayerVo vo) {
        Player player = new Player();
        BeanUtils.copyProperties(vo,player);
        int insert = baseMapper.insert(player);
        if(insert>0)
            return true;
        return false;
    }

    @Override
    public boolean removePlayer(String playerId) {
        int i = baseMapper.deleteById(playerId);
        if(i>0)
            return true;
        return false;
    }

    @Override
    public boolean updatePlayer(PlayerVo vo) {
        String id = vo.getId();
        QueryWrapper<Player> wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        Player player = new Player();
        BeanUtils.copyProperties(vo,player);
        int update = baseMapper.update(player, wrapper);
        if(update>0)
            return true;
        return false;
    }
}
